//
//  XS_FastLearnItemCell.swift
//  XueDao
//
//  Created by fandongtongxue on 2020/12/9.
//

import UIKit

protocol XS_FastLearnItemCellDelegate {
    func fastLearnItemCell(fastLearnItemCell : XS_FastLearnItemCell, didClickFavoriteBtn:UIButton)
}

class XS_FastLearnItemCell: UICollectionViewCell {
    
    var delegate : XS_FastLearnItemCellDelegate?
    
    var _model : XS_FastLearnItemModel!
    public var model : XS_FastLearnItemModel!{
        set{
            _model = newValue
            //设置数据
            favoriteBtn.isSelected = true
            imgView.sd_setImage(with: URL.init(string: newValue.imgUrl), completed: nil)
            titleLabel.text = newValue.title
            contentLabel.text = newValue.collectCount + "人已收藏"
        }
        get{
            return _model
        }
    }

    @IBOutlet weak var favoriteBtn: UIButton!
    @IBOutlet weak var imgView: UIImageView!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var contentLabel: UILabel!
    @IBOutlet weak var bgView: UIView!
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        layer.masksToBounds = true
        layer.cornerRadius = .scale * 4
        bgView.backgroundColor = UIColor(red: 0.03, green: 0, blue: 0, alpha: 0.49)
        favoriteBtn.imageEdgeInsets = UIEdgeInsets.init(top: 6, left: 0, bottom: 6, right: 0)
        favoriteBtn.imageView!.contentMode = .scaleAspectFit
        favoriteBtn.layer.backgroundColor = UIColor(red: 0.03, green: 0, blue: 0, alpha: 0.49).cgColor
        let shapeLayer = CAShapeLayer()
        shapeLayer.fillColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
        shapeLayer.path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 62, height: 28), byRoundingCorners: .bottomLeft, cornerRadii: CGSize(width: 8, height: 8)).cgPath
        favoriteBtn.layer.mask = shapeLayer
    }

    @IBAction func favoriteBtnAction(_ sender: UIButton) {
        if delegate != nil {
            delegate?.fastLearnItemCell(fastLearnItemCell: self, didClickFavoriteBtn: sender)
        }
    }
}
